package com.magnificent.atlantis.server.event;

import com.magnificent.commons.utils.collections.list.MetaArrayList;
import com.magnificent.commons.utils.collections.list.MetaList;

/**
 * User: Babanin
 * Date: Oct 3, 2009
 * Time: 12:06:16 AM
 */
public class EventDispatcher {
    private static EventDispatcher instance;
    private MetaList<EventDispatcherListener> listeners;

    private EventDispatcher() {
        this.listeners = new MetaArrayList<EventDispatcherListener>();
    }

    public void addListener(EventDispatcherListener listener) {
        listeners.add(listener);
    }

    public void postEvent(EventType eventType, Event event) {
        for (EventDispatcherListener listener : listeners) {
            listener.newEvent(eventType, event);
        }
    }

    public static EventDispatcher getInstance() {
        if (instance == null) {
            instance = new EventDispatcher();
        }

        return instance;
    }
}
